<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .d1,.d2{
            border: 1px solid black;
            padding: 5px;
            width: fit-content;
            font-size: 14px;
            margin-top: 10px;
        }
        .lishi{
            margin-top: 10px;
        }
        .faxian{
            margin-top: 20px;
        }
        input{
            width: 300px;
            height: 25px;
        }
        .ddd{
            display: flex;
        }
        section .d1{
            margin-left: 10px;
        }
    </style>
</head>
<body>
    <section  id="app">
        <h2>搜索</h2>
        <input type="text" placeholder="搜索商品名称" v-model="inputtext">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span @click="sousuo">搜索</span>
        <div class="lishi" >
            <span>历史搜索</span> &nbsp;&nbsp; <span @click="qingkong">清空</span>
            <div class="ddd" >
                <div class="d1" v-for="(item,index) in shuju" v-bind:key="index">{{item.name}}</div>
            </div>
        </div>
        <div class="faxian">
            <span>搜索发现</span>
            <div class="d2">麻辣烫</div>
        </div>
    </section>
</body>
</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v= new Vue({
        el:'#app',
        data:{
            inputtext:'',
            shuju:[]
        },
        methods:{
            sousuo(){
                if(this.inputtext){
                    var obj={
                        name:this.inputtext
                    }
                    this.shuju.push(obj)
                    this.inputtext=''
                }
                console.log(this.shuju);
                console.log('aaaa');
            },
            qingkong(){
                this.shuju=[]
            }
        }
    })
</script>